package cn.edu.seu.herald.informationplatform.filter;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import cn.edu.seu.herald.informationplatform.bean.league.Album;
import cn.edu.seu.herald.informationplatform.bean.league.Linked;

public class LinkedAlbumAdapter {
	
	private static final String BASE_LINK_URL = "";
	
	private static LinkedAlbumAdapter _instances;
	
	public static LinkedAlbumAdapter getInstance() {
		initialize();
		return _instances;
	}
	
	private static void initialize() {
		if (_instances == null) {
			_instances = new LinkedAlbumAdapter();
		}
	}
	
	private static String getLinkString(int albumId) {
		return BASE_LINK_URL + albumId;
	}
	
	protected LinkedAlbumAdapter() {}
	
	public Linked<Album> adapt(Album  album, int key) {
		Linked<Album> linked = new Linked<Album>();
		linked.setLink(getLinkString(key));
		linked.setEntity(album);
		return linked;
	}
	
	public List<Linked<Album>> adapt(
			Map<Integer, Album> albumMapping) {
		List<Linked<Album>> adaptor =
				new LinkedList<Linked<Album>>();
		for (Entry<Integer, Album> entry: albumMapping.entrySet()) {
			int key = entry.getKey();
			Album value = entry.getValue();
			Linked<Album> linked = adapt(value, key);
			adaptor.add(linked);
		}
		return adaptor;
	}

}
